import axios from "axios";

export const request = axios.create({
    baseURL:"/dev-api",
    timeout:5000
})
function loadToken(){
    if(sessionStorage.getItem("token")){
        return sessionStorage.getItem("token")
    }else{
        return localStorage.getItem("token")
    }
}
//请求拦截器
request.interceptors.request.use(req => {
    const token = loadToken()
    if(token){
        req.headers['Authorization'] = `Bearer ${token}`
    }
    return req
})
//响应拦截器
request.interceptors.response.use(
    function(response){
        const resp = response.data;
        if(resp.code != 0){
            console.log("失败");
            
        }
        return response.data
    },
    function(err) {
       console.log(err);
       
    }
)

